{$CLEO .cs}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "RLOTSCR"

// By ArtemQa146


//  cleo+
if
    0AA2: 31@ = load_dynamic_library "CLEO+.cleo"
then
    if
        0AA4: 30@ = get_dynamic_library_procedure "GetCleoPlusVersion" library 31@
    then
        0AA7: call_function_return 30@ num_params 0 pop 0 29@
        if
            not 29@ >= 0x1020000
        then
            0AD1: show_formatted_text_highpriority "Cleo+ 1.2.0 (or higher) version is required, the Weapon Details mod is disabled" time 15000
            0AA3: free_dynamic_library 31@
            0A93: terminate_this_custom_script
        end
        0AA3: free_dynamic_library 31@
    end
else
    0AD1: show_formatted_text_highpriority "Cleo+ 1.2.0 (or higher) version is required, the Weapon Details mod is disabled" time 15000
    0AA3: free_dynamic_library 31@
    0A93: terminate_this_custom_script
end

const
    Sprite_texture = 31@
    back_texture = 28@
    progress = 30@
    check = 29@
    scale_xy = 27@
    alpha_black = 26@
    bit_set = 25@
    without_x = 24@
    without_y = 23@
    ammo_icon = 22@
    R_ini = 21@
    G_ini = 20@
    B_ini = 19@
    sprite_texture_alt = 18@
    without_aim = 1
    ammo_icon_bit = 2
    Mode_1 = 3
    Mode_2 = 4
    Mode_3 = 5
    diss_cross = 6
    mode_4 = 7
    mode_5 = 8
end

gosub @Ini_sets

// Load texture
0390: load_txd_dictionary 'rloadq'
038F: load_texture "rlcrs" as 1
0E3C: get_texture_from_sprite 1 store_to Sprite_texture
038F: load_texture "rlcrs2" as 2
0E3C: get_texture_from_sprite 2 store_to back_texture
038F: load_texture "rlcrs3" as 3
0E3C: get_texture_from_sprite 3 store_to ammo_icon
038F: load_texture "rlcrs4" as 4
0E3C: get_texture_from_sprite 4 store_to sprite_texture_alt
0391: release_textures

while true
wait 0
    if
        player.Defined(0)
    then
    
        if
            0ADC:   test_cheat "RLOTSCR"
        then
            gosub @Ini_Sets
            03E5: show_text_box 'CHEAT1'
            wait 500
            continue
        end

        if or
            0E25: is_on_cutscene
            0EB7: is_on_scripted_cutscene
        then
            continue
        end
    
        check = false
        
        //  
        if or
            Actor.Animation($PLAYER_ACTOR) == "rifle_load"
            Actor.Animation($PLAYER_ACTOR) == "rifle_crouchload"
            Actor.Animation($PLAYER_ACTOR) == "colt45_reload"
            Actor.Animation($PLAYER_ACTOR) == "colt45_crouchreload"
            Actor.Animation($PLAYER_ACTOR) == "python_reload"
            Actor.Animation($PLAYER_ACTOR) == "python_crouchreload"
            Actor.Animation($PLAYER_ACTOR) == "UZI_reload"
            Actor.Animation($PLAYER_ACTOR) == "UZI_crouchreload"
        then
            gosub @Animation
            check = true
        end
        
        if or
            Actor.Animation($PLAYER_ACTOR) == "rifle_load"
            Actor.Animation($PLAYER_ACTOR) == "Rifle_load_m4"
            Actor.Animation($PLAYER_ACTOR) == "Rifle_load_m4_idle"
            Actor.Animation($PLAYER_ACTOR) == "rifle_crouchload"
            Actor.Animation($PLAYER_ACTOR) == "RIFLE_crouchload_m4"
            Actor.Animation($PLAYER_ACTOR) == "sawnoff_reload"
            Actor.Animation($PLAYER_ACTOR) == "buddy_reload"
            Actor.Animation($PLAYER_ACTOR) == "buddy_crouchreload"
        then
            gosub @Animation
            check = true
        end
        
        if or
            Actor.Animation($PLAYER_ACTOR) == "silence_reload"
            Actor.Animation($PLAYER_ACTOR) == "Crouchreload"
            Actor.Animation($PLAYER_ACTOR) == "AR15_crouchload"
            Actor.Animation($PLAYER_ACTOR) == "AR15_load"
            Actor.Animation($PLAYER_ACTOR) == "twobar_crouchreload"
            Actor.Animation($PLAYER_ACTOR) == "twobar_reload"
            Actor.Animation($PLAYER_ACTOR) == "flame_r"
        then
            gosub @Animation
            check = true
        end
        
        if or
            Actor.Animation($PLAYER_ACTOR) == "revlvr_crouchreload"
            Actor.Animation($PLAYER_ACTOR) == "revlvr_reload"
            Actor.Animation($PLAYER_ACTOR) == "BOLTSNP_load"
            Actor.Animation($PLAYER_ACTOR) == "BOLTSNP_crouchload"
        then
            gosub @Animation
            check = true
        end
    
    
        //    
        if
            check == true
        then
        
            //  
            0E64: get_camera_mode 1@
            
            if 1@ == 15 //    
            then continue
            end
            
            if or
                1@ == 7 // sniper
                1@ == 8 // rpg
                1@ == 46 // photo
                1@ == 51 // heatseak
                1@ == 4 //  ,    
                1@ == 45 //    
            then
                if
                    1@ == 4
                then
                    if
                        08B7:   test Bit_set bit without_aim
                    then
                        0087: 2@ = without_x // (float)
                        0087: 3@ = without_y // (float)
                    else
                        continue
                    end
                else
                    2@ = 320.0
                    3@ = 224.0
                end
            else
                0A8D: 2@ = read_memory 0xB6EC14 size 4 virtual_protect 0 //    by reaper
                0A8D: 3@ = read_memory 0xB6EC10 size 4 virtual_protect 0 //    by reaper
                0013: 2@ *= 640.0
                0013: 3@ *= 448.0
                1@ = 0
                if 08B7:   test Bit_set bit diss_cross
                then gosub @Cross //  
                end
            end
            
            

            if
                88B7:   not test Bit_set bit mode_5
            then
                0E1E: draw_texture_plus back_texture event 2 pos 2@ 3@ size scale_xy scale_xy angle 0.0 0 1 0 0 rgba 255 255 255 alpha_black //  
                
                if
                    08B7:   test Bit_set bit ammo_icon_bit
                then
                    0E1E: draw_texture_plus ammo_icon event 2 pos 2@ 3@ size scale_xy scale_xy angle 0.0 0 1 0 0 rgba 255 255 255 255
                end
            end
            
            
            
            // 
            
            
            
            if
                08B7:   test Bit_set bit mode_1
            then
                1@ = 0.0 //  
                for 0@ = 1 to 8 step 1 //  8 ,  

                    0E1E: draw_texture_plus Sprite_texture event 2 pos 2@ 3@ size scale_xy scale_xy angle 1@ 0 1 0 0 rgba R_ini G_ini B_ini 255 //  

                    gosub @Animation //    . 0,125   == 45,0 
                    if and
                        0@ == 1 // 
                        progress > 0.125 //  
                    then
                        1@ += 45.0 //  
                    end
                    if and
                        0@ == 2
                        progress > 0.25
                    then
                        1@ += 45.0
                    end
                    if and
                        0@ == 3
                        progress > 0.375
                    then
                        1@ += 45.0
                    end
                    if and
                        0@ == 4
                        progress > 0.5
                    then
                        1@ += 45.0
                    end
                    if and
                        0@ == 5
                        progress > 0.625
                    then
                        1@ += 45.0
                    end
                    if and
                        0@ == 6
                        progress > 0.75
                    then
                        1@ += 45.0
                    end
                    if and
                        0@ == 7
                        progress > 0.875
                    then
                        1@ += 45.0
                    end
                    if and
                        0@ == 8
                        progress > 0.98
                    then
                        1@ += 45.0
                    end
                end
            end
            
            
            
            //    
            
            
            
            if
                08B7:   test Bit_set bit mode_2
            then
                
                gosub @Animation //    . 0,125   == 45,0 
                progress *= 360.0
                progress -= 15.0
                
                0E1E: draw_texture_plus Sprite_texture event 2 pos 2@ 3@ size scale_xy scale_xy angle progress 0 1 0 0 rgba R_ini G_ini B_ini 255 //  

            end
            
            
            
            //  
            
            
            
            if
                08B7:   test Bit_set bit mode_3
            then
                1@ = 0.0 //  
                for 0@ = 0 to 12 step 1 //  8 ,  
                
                    0E1E: draw_texture_plus Sprite_texture event 2 pos 2@ 3@ size scale_xy scale_xy angle 1@ 0 1 0 0 rgba R_ini G_ini B_ini 255 //  

                    gosub @Animation //    . 0,125   == 45,0 
                    
                    if
                        0@ == 1 // 
                    then
                        if
                            progress > 0.083 //  
                        then
                            1@ += 30.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end
                    
                    if
                        0@ == 2 // 
                    then
                        if
                            progress > 0.166 //  
                        then
                            1@ += 30.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end
                    
                    if
                        0@ == 3 // 
                    then
                        if
                            progress > 0.249 //  
                        then
                            1@ += 30.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end
                    
                    if
                        0@ == 4 // 
                    then
                        if
                            progress > 0.332 //  
                        then
                            1@ += 30.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end
                    
                    if
                        0@ == 5 // 
                    then
                        if
                            progress > 0.415 //  
                        then
                            1@ += 30.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end
                    
                    if
                        0@ == 6 // 
                    then
                        if
                            progress > 0.498 //  
                        then
                            1@ += 30.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end
                    
                    if
                        0@ == 7 // 
                    then
                        if
                            progress > 0.581 //  
                        then
                            1@ += 30.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end
                    
                    if
                        0@ == 8 // 
                    then
                        if
                            progress > 0.664 //  
                        then
                            1@ += 30.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end
                    
                    if
                        0@ == 9 // 
                    then
                        if
                            progress > 0.747 //  
                        then
                            1@ += 30.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end
                    
                    if
                        0@ == 10 // 
                    then
                        if
                            progress > 0.83 //  
                        then
                            1@ += 30.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end
                    
                    if
                        0@ == 11 // 
                    then
                        if
                            progress > 0.913 //  
                        then
                            1@ += 30.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end
                    
                    if
                        0@ == 12 // 
                    then
                        if
                            progress > 0.913 //  
                        then
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end

                end
            end
            
            
            
            
            //    
            
            
            
             if
                08B7:   test Bit_set bit mode_4
            then
                1@ = 0.0 //  
                for 0@ = 0 to 8 step 1 //  8 ,  

                    0E1E: draw_texture_plus Sprite_texture event 2 pos 2@ 3@ size scale_xy scale_xy angle 1@ 0 1 0 0 rgba R_ini G_ini B_ini 255 //  

                    gosub @Animation //    . 0,125   == 45,0 

                    if
                        0@ == 1 // 
                    then
                        if
                            progress > 0.125 //  
                        then
                            1@ += 45.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end

                    if
                        0@ == 2 // 
                    then
                        if
                            progress > 0.25 //  
                        then
                            1@ += 45.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end

                    if
                        0@ == 3 // 
                    then
                        if
                            progress > 0.375 //  
                        then
                            1@ += 45.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end

                    if
                        0@ == 4 // 
                    then
                        if
                            progress > 0.5 //  
                        then
                            1@ += 45.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end

                    if
                        0@ == 5 // 
                    then
                        if
                            progress > 0.625 //  
                        then
                            1@ += 45.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end

                    if
                        0@ == 6 // 
                    then
                        if
                            progress > 0.75 //  
                        then
                            1@ += 45.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end

                    if
                        0@ == 7 // 
                    then
                        if
                            progress > 0.875 //  
                        then
                            1@ += 45.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end

                    if
                        0@ == 8 // 
                    then
                        if
                            progress > 0.98 //  
                        then
                            1@ += 45.0 //  
                        else
                            progress *= 360.0
                            0087: 1@ = progress // (float)
                        end
                    end

                end
            end
            
            
            //    



            if
                08B7:   test Bit_set bit mode_5
            then

                gosub @Animation //    . 0,125   == 45,0 
                0087: 1@ = progress // (float)
                0087: 5@ = progress // (float)
                
                0085: 6@ = alpha_black // (int)
                008F: 6@ = integer 6@ to_float

                if
                    progress <= 0.35
                then
                    1@ *= 255.0
                    1@ *= 3.0
                    if 1@ >= 255.0
                    then 1@ = 255.0
                    end
                    if 1@ <= 0.0
                    then 1@ = 0.0
                    end
                    
                    5@ *= 255.0
                    5@ *= 2.0
                    if 0035:   5@ >= 6@  // (float)
                    then 0087: 5@ = 6@ // (float)
                    end
                    if 5@ <= 0.0
                    then 5@ = 0.0
                    end
                else
                    if
                        progress >= 0.7
                    then
                        1@ *= 255.0
                        1@ *= 3.5
                        4@ = 893.0
                        0063: 4@ -= 1@  // (float)
                        if 4@ >= 255.0
                        then 4@ = 255.0
                        end
                        if 4@ <= 0.0
                        then 4@ = 0.0
                        end
                        0087: 1@ = 4@ // (float)
                        
                        
                        5@ *= 255.0
                        5@ *= 4.0
                        4@ = 1000.0
                        0063: 4@ -= 5@  // (float)
                        if 0035:   4@ >= 6@  // (float)
                        then 0087: 4@ = 6@ // (float)
                        end
                        if 4@ <= 0.0
                        then 4@ = 0.0
                        end
                        0087: 5@ = 4@ // (float)
                    else
                        1@ = 255.0
                        0087: 5@ = 6@ // (float)
                    end
                end
                
                008E: 1@ = float 1@ to_integer
                008E: 5@ = float 5@ to_integer
                progress *= 360.0
                progress -= 15.0
                progress *= 1.2
                if progress < -18.0
                then progress = -15.0
                end
                
                if
                    08B7:   test Bit_set bit ammo_icon_bit
                then
                    0E1E: draw_texture_plus ammo_icon event 2 pos 2@ 3@ size scale_xy scale_xy angle 0.0 0 1 0 0 rgba 255 255 255 1@
                end

                0E1E: draw_texture_plus back_texture event 2 pos 2@ 3@ size scale_xy scale_xy angle 0.0 0 1 0 0 rgba 255 255 255 5@ //  
                

                0E1E: draw_texture_plus sprite_texture_alt event 2 pos 2@ 3@ size scale_xy scale_xy angle progress 0 1 0 0 rgba R_ini G_ini B_ini 1@ //  

            end
            
            
        else
            0A8D: 1@ = read_memory 0x58E287 size 1 virtual_protect 0 //   ,  
            if
                1@ == 0
            then
                1@ = 255
                if 08B7:   test Bit_set bit diss_cross
                then gosub @Cross //  
                end
            end
        end
    end
end

:Animation
if Actor.Animation($PLAYER_ACTOR) == "rifle_load"
then 0613: progress = actor $PLAYER_ACTOR animation "rifle_load" time
end
if Actor.Animation($PLAYER_ACTOR) == "rifle_crouchload"
then 0613: progress = actor $PLAYER_ACTOR animation "rifle_crouchload" time
end
if Actor.Animation($PLAYER_ACTOR) == "colt45_reload"
then 0613: progress = actor $PLAYER_ACTOR animation "colt45_reload" time
end
if Actor.Animation($PLAYER_ACTOR) == "colt45_crouchreload"
then 0613: progress = actor $PLAYER_ACTOR animation "colt45_crouchreload" time
end
if Actor.Animation($PLAYER_ACTOR) == "python_reload"
then 0613: progress = actor $PLAYER_ACTOR animation "python_reload" time
end
if Actor.Animation($PLAYER_ACTOR) == "python_crouchreload"
then 0613: progress = actor $PLAYER_ACTOR animation "python_crouchreload" time
end
if Actor.Animation($PLAYER_ACTOR) == "rifle_load"
then 0613: progress = actor $PLAYER_ACTOR animation "rifle_load" time
end
if Actor.Animation($PLAYER_ACTOR) == "rifle_crouchload"
then 0613: progress = actor $PLAYER_ACTOR animation "rifle_crouchload" time
end
if Actor.Animation($PLAYER_ACTOR) == "Rifle_load_m4"
then 0613: progress = actor $PLAYER_ACTOR animation "Rifle_load_m4" time
end
if Actor.Animation($PLAYER_ACTOR) == "Rifle_load_m4_idle"
then 0613: progress = actor $PLAYER_ACTOR animation "Rifle_load_m4_idle" time
end
if Actor.Animation($PLAYER_ACTOR) == "RIFLE_crouchload_m4"
then 0613: progress = actor $PLAYER_ACTOR animation "RIFLE_crouchload_m4" time
end
if Actor.Animation($PLAYER_ACTOR) == "UZI_reload"
then 0613: progress = actor $PLAYER_ACTOR animation "UZI_reload" time
end
if Actor.Animation($PLAYER_ACTOR) == "UZI_crouchreload"
then 0613: progress = actor $PLAYER_ACTOR animation "UZI_crouchreload" time
end
if Actor.Animation($PLAYER_ACTOR) == "sawnoff_reload"
then 0613: progress = actor $PLAYER_ACTOR animation "sawnoff_reload" time
end
if Actor.Animation($PLAYER_ACTOR) == "buddy_reload"
then 0613: progress = actor $PLAYER_ACTOR animation "buddy_reload" time
end
if Actor.Animation($PLAYER_ACTOR) == "buddy_crouchreload"
then 0613: progress = actor $PLAYER_ACTOR animation "buddy_crouchreload" time
end
if Actor.Animation($PLAYER_ACTOR) == "silence_reload"
then 0613: progress = actor $PLAYER_ACTOR animation "silence_reload" time
end
if Actor.Animation($PLAYER_ACTOR) == "Crouchreload"
then 0613: progress = actor $PLAYER_ACTOR animation "Crouchreload" time
end
if Actor.Animation($PLAYER_ACTOR) == "AR15_crouchload"
then 0613: progress = actor $PLAYER_ACTOR animation "AR15_crouchload" time
end
if Actor.Animation($PLAYER_ACTOR) == "AR15_load"
then 0613: progress = actor $PLAYER_ACTOR animation "AR15_load" time
end
if Actor.Animation($PLAYER_ACTOR) == "twobar_reload"
then 0613: progress = actor $PLAYER_ACTOR animation "twobar_reload" time
end
if Actor.Animation($PLAYER_ACTOR) == "twobar_crouchreload"
then 0613: progress = actor $PLAYER_ACTOR animation "twobar_crouchreload" time
end
if Actor.Animation($PLAYER_ACTOR) == "flame_r"
then 0613: progress = actor $PLAYER_ACTOR animation "flame_r" time
end
if Actor.Animation($PLAYER_ACTOR) == "revlvr_reload"
then 0613: progress = actor $PLAYER_ACTOR animation "revlvr_reload" time
end
if Actor.Animation($PLAYER_ACTOR) == "revlvr_crouchreload"
then 0613: progress = actor $PLAYER_ACTOR animation "revlvr_crouchreload" time
end
if Actor.Animation($PLAYER_ACTOR) == "BOLTSNP_load"
then 0613: progress = actor $PLAYER_ACTOR animation "BOLTSNP_load" time
end
if Actor.Animation($PLAYER_ACTOR) == "BOLTSNP_crouchload"
then 0613: progress = actor $PLAYER_ACTOR animation "BOLTSNP_crouchload" time
end
return

:Cross
0A8C: write_memory 0x58E287 size 1 value 1@ virtual_protect 0 //a by vladvo
0A8C: write_memory 0x58E2EC size 1 value 1@ virtual_protect 0 //a by vladvo
0A8C: write_memory 0x58E3BF size 1 value 1@ virtual_protect 0 //a by vladvo
0A8C: write_memory 0x58E420 size 1 value 1@ virtual_protect 0 //a by vladvo
0A8C: write_memory 0x58E461 size 1 value 1@ virtual_protect 0 //a by vladvo
return

:Ini_sets
0AF2: scale_xy = read_float_from_ini_file "cleo\Reloading on the screen.ini" section "Settings" key "Scale"
0AF2: without_x = read_float_from_ini_file "cleo\Reloading on the screen.ini" section "Settings" key "Without aiming X"
0AF2: without_y = read_float_from_ini_file "cleo\Reloading on the screen.ini" section "Settings" key "Without aiming Y"
0AF0: alpha_black = read_int_from_ini_file "cleo\Reloading on the screen.ini" section "Settings" key "Alpha Black"

0AF0: R_ini = read_int_from_ini_file "cleo\Reloading on the screen.ini" section "Settings" key "R color"
0AF0: G_ini = read_int_from_ini_file "cleo\Reloading on the screen.ini" section "Settings" key "G color"
0AF0: B_ini = read_int_from_ini_file "cleo\Reloading on the screen.ini" section "Settings" key "B color"

08C3: clear Bit_set bit without_aim
0AF0: 0@ = get_int_from_ini_file "CLEO\Reloading on the screen.ini" section "Settings" key "Without aiming"
if 0@ == 1
then 08BD: set Bit_set bit without_aim
end

08C3: clear Bit_set bit ammo_icon_bit
0AF0: 0@ = get_int_from_ini_file "CLEO\Reloading on the screen.ini" section "Settings" key "The ammunition icon"
if 0@ == 1
then 08BD: set Bit_set bit ammo_icon_bit
end

08C3: clear Bit_set bit diss_cross
0AF0: 0@ = get_int_from_ini_file "CLEO\Reloading on the screen.ini" section "Settings" key "Disable the crosshair"
if 0@ == 1
then 08BD: set Bit_set bit diss_cross
end

08C3: clear Bit_set bit Mode_1
08C3: clear Bit_set bit Mode_2
08C3: clear Bit_set bit Mode_3
08C3: clear Bit_set bit Mode_4
08C3: clear Bit_set bit Mode_5
0AF0: 0@ = get_int_from_ini_file "CLEO\Reloading on the screen.ini" section "Settings" key "Mode"
if 0@ == 1
then 08BD: set Bit_set bit Mode_1
end
if 0@ == 2
then 08BD: set Bit_set bit Mode_2
end
if 0@ == 3
then 08BD: set Bit_set bit Mode_3
end
if 0@ == 4
then 08BD: set Bit_set bit Mode_4
end
if 0@ == 5
then 08BD: set Bit_set bit Mode_5
end
return